package com.headwind.logistics.common.controller;

import com.headwind.logistics.common.util.getV4IPUtil;
import com.headwind.logistics.common.pojo.Employee;
import com.headwind.logistics.permission.service.intl.EmployeeServiceIntl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author 小恶魔
 * 公共跳转网页控制器
 * @time 2020-7-11
 *
 */
@Controller
public class IndexController {

    @Autowired
    private EmployeeServiceIntl employeeServiceIntl;


    /**
     * 跳转后台首页
     * @return
     */
    @RequestMapping(value = "/admin/index",method = RequestMethod.GET)
    public String toAdminIndex(HttpSession session, Model model){

        return "/admin/index";
    }

    /**
     * 树形菜单
     * @param session
     * @return
     */
    @RequestMapping("/admin/menu")
    @ResponseBody
    public Map<String,Object> menu(HttpSession session){

        Employee employee = (Employee) session.getAttribute("EMPLOYEE");

        return employeeServiceIntl.queryMenusByEmployeeNo(employee.getEmployeeNo());
    }

    /**
     * 跳转后台的登录界面
     * @return
     */
    @RequestMapping(value = "/admin/login",method = RequestMethod.GET)
    public String toAdminLogin(){


        return "/admin/login";
    }

    /**
     * 跳转至前台首页
     * @return
     */
    @GetMapping(value = {"/","/index"})
    public String toIndex(){

        System.out.println(getV4IPUtil.getV4IP());

        return "/index";
    }

    /**
     * 跳转至登录界面
     * @return
     */
    @GetMapping("/toLogin")
    public String toLogin(){

        return "/login";
    }


}
